package fr.cpe.dp.projet2.model.musicBuilder;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiEvent;
import javax.sound.midi.Sequence;
import javax.sound.midi.Track;

/**
 *
 * @author Benoit
 */
public class RandomBuilder extends AbstractMusicBuilder {
	@Override
    public Sequence generateSequence() {
        Sequence seq = null;
        try {
            seq = new Sequence(Sequence.PPQ, 4);
            Track piste = seq.createTrack();
            int r = 0;
            for (int i = 0; i < 100; i += 4) {
                r = (int) ((Math.random() * 50) + 1);
                piste.add(makeEvent(144, 1, r, 100, i));
                piste.add(makeEvent(176, 1, 127, 0, i));
                piste.add(makeEvent(128, 1, r, 100, i + 2));
            }
        } catch (InvalidMidiDataException ex) {
            Logger.getLogger(RandomBuilder.class.getName()).log(Level.SEVERE, null, ex);
        }
        return seq;
    }
}
